<!DOCTYPE html>
<html>
<title>字符串的使用</title>

<body>

    <script>
        var str = "六百六十六";
        document.write(str.length + "<br>");
        var str2 = "村正";
        var str3 = str + str2 + "<br>";
        document.write(str3);
        var str4 = "你是\'zako\' ";
        document.write(str4 + "<br>");
        var str5 = "1234\n5678\r9123\v4567"
        document.write(str5 + "<br>");
        alert(str5);
        var str6 = `11
        2
        334
        4
        5
        31
        
        12
        `
        document.write(str6 + "<br>" + "<hr>");

        var city = new String("New Delhi");
        document.write(city + "<hr>");

        var a = "NI";
        var b = "KO";
        var c = a.concat(b);
        document.write(c + "<br>");
        var upper = "SPA";
        var lower = upper.toLowerCase();
        document.write(upper + "<br>" + lower + "<br>");
        var strr = "so,YOU will abandon me ,abandon   ?";
        document.write(strr.indexOf('abandon') + "<br>");
        document.write(strr.lastIndexOf('abandon') + "<br>");
        var p = strr.search(/you/i);
        /*
        // g - global（全局匹配）
str.match(/to be/g);    // 查找所有匹配

// i - ignore case（忽略大小写）
str.match(/to be/i);    // 不区分大小写

// m - multiline（多行匹配）
str.match(/^to be/m);   // 匹配每行开头

// 可以组合使用
str.match(/to be/gi);   // 全局+忽略大小写
        */
        document.write(p + "<br>" + "<hr>");
        document.write("查找字串<br>");
        var st = "can you help me?";
        var arr = st.split(" ");
        for (x of arr) {
            document.write(x + "<br>");
        }

        var greeting = "     hello WORLD      ";
        greeting.trim();
        document.write("<br>去掉前后空格" + greeting + "<br>");
        var g2 = greeting.replace('hello', 'Ciallo~');
        document.write("<br>replace:" + g2 + "<br>");
        var g3 = greeting.replace(/world/gi, 'ZZZ');
        document.write("<br>全局忽略大小写replace:" + g3 + "<br>");
        var ext = greeting.slice(1, 5); //用负号倒着也可以  如果取单个括号里就一个数字
        document.write("<br>slice:" + ext + "<br>");
        var sttt = greeting.substring(1, 5); //不能负号
        document.write("<br>substring:" + sttt + "<br>");
        var srtt = greeting.substring(2); //如果省略第二个参数，则substring()method将提取字符串的其余部分
        document.write("<br>substring:" + srtt + "<br>");
        var sss = greeting.substr(2, 5); //从2开始 向后取5个
        document.write("<br>substr:" + sss + "<br>");
        document.write("<br><hr><br>查找字符");
        var ppp = greeting.charAt(1);
        document.write("<br>" + ppp + "<br>");
        var plpl = greeting.charCodeAt(1);
        document.write("<br>" + plpl + "<br>");
    </script>

</body>

</html>